package com.fowo.api.syncAmazon.service.impl;

import com.fowo.api.syncAmazon.api.FBAInventoryReportService;
import com.fowo.api.syncAmazon.mapper.AmazonTmpMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class SyncFbaInventoryServiceImpl {
    @Resource
    private FBAInventoryReportService fbaInventoryReportService;
    @Resource
    private AmazonTmpMapper amazonTmpMapper;

    /**
     * 同步库存
     * @throws Exception
     */
    public void syncFbaInventory() throws Exception {
        //删除临时表数据
        amazonTmpMapper.deleteFbaInventory();
        //拉去数据到临时表
        fbaInventoryReportService.getFbaInventory();
        //同步到业务表
        amazonTmpMapper.updateFbaInventory();
        amazonTmpMapper.insertFbaInventory();
    }

    /**
     * 同步库龄数据
     * @throws Exception
     */
    public void syncInventoryAge() throws Exception {
        //删除临时表数据
        amazonTmpMapper.deleteFbaInventory();
        //拉去数据到临时表
        fbaInventoryReportService.getFbaInventoryAge();
        //同步到业务表
        amazonTmpMapper.updateFbaInventoryAge();
    }
}
